package com.chat.login.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chat.common.common.exception.RoutineException;
import com.chat.common.entity.Version;
import com.chat.login.mapper.VersionMapper;
import com.chat.login.service.IVersionService;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author weikjie
 * @since 2024-05-23
 */
@Service
public class VersionServiceImpl extends ServiceImpl<VersionMapper, Version> implements IVersionService {

    @Override
    public Version getNewVersion() {
        LambdaQueryWrapper<Version> wrapper = new LambdaQueryWrapper<>();
        wrapper.orderByDesc(Version::getCreationTime).last("limit 1");
        Version latestVersion = getOne(wrapper);
        if(latestVersion == null) {
            throw new RoutineException("暂无最新版本");
        }
        return latestVersion;
    }
}
